<template>
    <a-modal :title="$t('设置数据压缩')" v-model='isShow' @cancel='handleClose' width='520px' @ok='handleCreate'
        :cancelText="$t('Cancel')" :okText="$t('Save')" :maskClosable='false' v-dragModal>
        <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol">
            <a-spin :spinning="loading">
                <a-form-model-item :label="$t('数据压缩')" prop="open">
                    <a-switch size="small" v-model="form.open" />
                </a-form-model-item>
                <a-form-model-item v-show="form.open" :label="$t('压缩算法')" prop="snappy">
                    <a-radio disabled checked :value="1" />snappy
                </a-form-model-item>
                <a-form-model-item>
                    <div style="margin-left: 12%;">
                        <Iconfont class="icon table-operation-icon" type="a-16_f_ic_about"></Iconfont>
                        <span>{{ $t('启动数据压缩后：默认采用snappy压缩数据') }}</span>
                    </div>
                </a-form-model-item>
            </a-spin>
        </a-form-model>
    </a-modal>
</template>

<script>
export default {
    data() {
        return {
            isShow: false,
            loading: false,
            labelCol: { span: 6 },
            wrapperCol: { span: 18 },
            form: {
                pool: '',
                open: false,
                algorithm: 1
            },
            rules: {

            },
        };
    },
    methods: {
        async getList() {
            const { data } = await this.$api.pool.getPoolCompressionApi({ pool: this.form.pool })
            const item = data.params[0]
            this.form.open = item.open
        },
        handleCreate() {
            this.$refs.ruleForm.validate(async valid => {
                if (valid) {
                    const { pool, open } = this.form
                    this.loading = true
                    const { data } = await this.$api.pool.setPoolCompressionApi({ pool, open })
                    this.model(data.id) //返回模板
                    this.notice(data.id, data.params, data.flag) //通知列表显示
                    if (data.flag == '0') {
                        this.handleClose()
                    }
                    this.loading = false
                } else {
                    return false;
                }
            });
        },
        handleClose() {
            this.$refs['ruleForm'].resetFields();
            this.isShow = false
        },
    }
}
</script>
